package com.yzt.dynamicmodule.modle;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.home.IndexBaseBean;
import com.yzt.zhuju.network.entity.home.IndexDataBean;
import com.rxjava.rxlife.ScopeViewModel;

import java.util.List;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   : 首页发现的数据模型
 */
public class DiscoverViewModel extends ScopeViewModel {

    /**
     * 获取列表成功
     */
    public MutableLiveData<List<IndexDataBean>> friendListSuccessEvent = new MutableLiveData<>();

    /**
     * 获取列表成功
     */
    public MutableLiveData<Boolean> friendListFinallyEndEvent = new MutableLiveData<>();

    public DiscoverViewModel(@NonNull Application application) {
        super(application);
    }

    public void getIndexDiscover(int extraType, String cityCode, String lat, String lng, int currentPage, int pageSize) {
        // 类型 1-发现 2-热门 3-关注
        BizLayer.getInstance().getIndexModule().getIndexUserList(extraType, cityCode, lat, lng, currentPage, pageSize, new AresSubscriber<IndexBaseBean>() {
            @Override
            protected void onSuccess(IndexBaseBean list) {
                if (list != null && !list.getList().isEmpty()) {
                    list.getList().get(0).setCheck(true);
                }
                friendListSuccessEvent.postValue(list.getList());
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
                friendListFinallyEndEvent.postValue(true);
            }
        });
    }

    public void getIndexDiscover(String userId, String dynamicId, int currentPage, int pageSize) {
        // 类型 1-发现 2-热门 3-关注
        BizLayer.getInstance().getIndexModule().getIndexUserList(userId, dynamicId, currentPage, pageSize, new AresSubscriber<IndexBaseBean>() {
            @Override
            protected void onSuccess(IndexBaseBean list) {
                if (list != null && !list.getMomentList().isEmpty()) {
                    list.getMomentList().get(0).setCheck(true);
                }
                friendListSuccessEvent.postValue(list.getMomentList());
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
                friendListFinallyEndEvent.postValue(true);
            }
        });
    }
}